Pencil-whipped the remaining OLDGPX cases and convinced myself we'd delivered
authorrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 9 Mar 2013 21:45:22 +0000 (21:45 +0000)
committerrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 9 Mar 2013 21:45:22 +0000 (21:45 +0000)
parity.  Removed fprintf style output totally in favor in Qt XML serializer.

git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4342 f51c46e8-681c-474f-0cfe-069cfd0219fb

gpsbabel/garmin_fs.cc
gpsbabel/garmin_fs.h
gpsbabel/gpx.cc

index 38efa926d5c57d84578685159df9196d52b85d0f..3e6491beac09fbcf0a9dd8917da7e3a5d205dba4 100644 (file)
@@ -185,7 +185,7 @@ void garmin_fs_convert(void* fs)
 /* GPX - out */
 
 void
-garmin_fs_xml_fprint(gbfile* ofd, const waypoint* waypt,
+garmin_fs_xml_fprint(const waypoint* waypt,
                      QXmlStreamWriter& writer)
 {
   const char* phone, *addr;
@@ -218,11 +218,6 @@ garmin_fs_xml_fprint(gbfile* ofd, const waypoint* waypt,
       WAYPT_HAS(waypt, proximity) ||
       WAYPT_HAS(waypt, temperature) ||
       gmsd->flags.display) {
-    int space = 1;
-#if OLDGPX
-    gbfprintf(ofd, "%*s<extensions>\n", space++ * 2, "");
-    gbfprintf(ofd, "%*s<gpxx:WaypointExtension %s\">\n", space++ * 2, "", GARMIN_GPX_EXT_REFERENCE);
-#else
     writer.writeStartElement("extensions");
     writer.writeStartElement("gpxx:WaypointExtension");
     writer.writeNamespace("http://www.garmin.com/xmlschemas/GpxExtensions/v3",
@@ -232,27 +227,14 @@ garmin_fs_xml_fprint(gbfile* ofd, const waypoint* waypt,
     writer.writeAttribute("xsi:schemaLocation",
       "http://www.garmin.com/xmlschemas/GpxExtensions/v3 "
       "http://www.garmin.com/xmlschemas/GpxExtensions/v3/GpxExtensionsv3.xsd");
-#endif
     if WAYPT_HAS(waypt, proximity) {
-#if OLDGPX
-      gbfprintf(ofd, "%*s<gpxx:Proximity>%.6f</gpxx:Proximity>\n", space * 2, "", waypt->proximity);
-#else
       writer.writeTextElement("gpxx:Proximity", QString::number(waypt->proximity, 'f', 6));
-#endif
     }
     if WAYPT_HAS(waypt, temperature) {
-#if OLDGPX
-      gbfprintf(ofd, "%*s<gpxx:Temperature>%.6f</gpxx:Temperature>\n", space * 2, "", waypt->temperature);
-#else
       writer.writeTextElement("gpxx:Temperature",  QString::number(waypt->temperature, 'f', 6));
-#endif
     }
     if WAYPT_HAS(waypt, depth) {
-#if OLDGPX
-      gbfprintf(ofd, "%*s<gpxx:Depth>%.6f</gpxx:Depth>\n", space * 2, "", waypt->depth);
-#else
       writer.writeTextElement("gpxx:Depth", QString::number(waypt->depth, 'f', 6));
-#endif
     }
     if (gmsd->flags.display) {
       const char* cx;
@@ -267,114 +249,48 @@ garmin_fs_xml_fprint(gbfile* ofd, const waypoint* waypt,
         cx = "SymbolAndName";
         break;
       }
-#if OLDGPX
-      gbfprintf(ofd, "%*s<gpxx:DisplayMode>%s</gpxx:DisplayMode>\n", space * 2, "", cx);
-#else
       writer.writeTextElement("gpxx:DisplayMode", cx);
-#endif
     }
     if (gmsd->flags.category && gmsd->category) {
       int i;
       gbuint16 cx = gmsd->category;
-#if OLDGPX
-      gbfprintf(ofd, "%*s<gpxx:Categories>\n", space++ * 2, "");
-#else
       writer.writeStartElement("gpxx:Categories");
-#endif
       for (i = 0; i < 16; i++) {
         if (cx & 1) {
-#if OLDGPX
-          gbfprintf(ofd, "%*s<gpxx:Category>Category %d</gpxx:Category>\n", space*2, "", i+1);
-#else
           writer.writeTextElement("gpxx:Category", QString("Category %1").arg(i+1));
-#endif
         }
         cx = cx >> 1;
       }
-#if OLDGPX
-      gbfprintf(ofd, "%*s</gpxx:Categories>\n", --space * 2, "");
-#else
       writer.writeEndElement(); // gpxx:Categories
-#endif
     }
     if (*addr) {
       char* str;
-#if OLDGPX
-      char* tmp;
-      gbfprintf(ofd, "%*s<gpxx:Address>\n", space++ * 2, "");
-#else
       writer.writeStartElement("gpxx:Address");
-#endif
 
       if ((str = GMSD_GET(addr, NULL))) {
-#if OLDGPX
-        tmp = xml_entitize(str);
-        gbfprintf(ofd, "%*s<gpxx:StreetAddress>%s</gpxx:StreetAddress>\n", space * 2, "", tmp);
-        xfree(tmp);
-#else
         writer.writeTextElement("gpxx:StreetAddress", str);
-#endif
       }
       if ((str = GMSD_GET(city, NULL))) {
-#if OLDGPX
-        tmp = xml_entitize(str);
-        gbfprintf(ofd, "%*s<gpxx:City>%s</gpxx:City>\n", space * 2, "", tmp);
-        xfree(tmp);
-#else
         writer.writeTextElement("gpxx:City", str);
-#endif
       }
       if ((str = GMSD_GET(state, NULL))) {
-#if OLDGPX
-        tmp = xml_entitize(str);
-        gbfprintf(ofd, "%*s<gpxx:State>%s</gpxx:State>\n", space * 2, "", tmp);
-        xfree(tmp);
-#else
         writer.writeTextElement("gpxx:State", str);
-#endif
       }
       if ((str = GMSD_GET(country, NULL))) {
-#if OLDGPX
-        tmp = xml_entitize(str);
-        gbfprintf(ofd, "%*s<gpxx:Country>%s</gpxx:Country>\n", space * 2, "", tmp);
-        xfree(tmp);
-#else
         writer.writeTextElement("gpxx:Country", str);
-#endif
       }
       if ((str = GMSD_GET(postal_code, NULL))) {
-#if OLDGPX
-        tmp = xml_entitize(str);
-        gbfprintf(ofd, "%*s<gpxx:PostalCode>%s</gpxx:PostalCode>\n", space * 2, "", tmp);
-        xfree(tmp);
-#else
         writer.writeTextElement("gpxx:PostalCode", str);
-#endif
       }
-#if OLDGPX
-      gbfprintf(ofd, "%*s</gpxx:Address>\n", --space * 2, "");
-#else
       writer.writeEndElement(); // /gpxx::Address
-#endif
     }
 
     if (*phone) {
-#if OLDGPX
-      char* tmp = xml_entitize(phone);
-      gbfprintf(ofd, "%*s<gpxx:PhoneNumber>%s</gpxx:PhoneNumber>\n", space * 2, "", tmp);
-      xfree(tmp);
-#else
       writer.writeTextElement("gpxx:PhoneNumber", phone);
-#endif
     }
 
-#if OLDGPX
-    gbfprintf(ofd, "%*s</gpxx:WaypointExtension>\n", --space * 2, "");
-    gbfprintf(ofd, "%*s</extensions>\n", --space * 2, "");
-#else
     writer.writeEndElement(); // /gpxx::WaypointExtension
     writer.writeEndElement(); // /extensions.
-#endif
   }
 
 }
index a050c21af744cc999a86b1ae12f079f31cd5b8d0..95b4e8e5cefacc067de8640660271325f4d5dd8f 100644 (file)
@@ -123,7 +123,7 @@ char* garmin_fs_xstrdup(const char* src, size_t size);
 /* for GPX */
 void garmin_fs_xml_convert(const int base_tag, int tag, const char* cdatastr, waypoint* waypt);
 class QXmlStreamWriter;
-void garmin_fs_xml_fprint(gbfile* ofd, const waypoint* waypt, QXmlStreamWriter&);
+void garmin_fs_xml_fprint(const waypoint* waypt, QXmlStreamWriter&);
 
 /* common garmin_fs utilities */
 
index 708bee58d8ecab44a955e75b01c076fe5c6ab5bd..093fa68e05875d83d2add34d633110a3826067ce 100644 (file)
@@ -289,7 +289,6 @@ gpx_write_gdata(gpx_global_entry* ge, const char* tag)
         (0 == strcmp(tag, "email"))) {
       break;
     }
-    gbfprintf(ofd, " ");
   }
   writer.writeEndElement();
 }
@@ -1378,8 +1377,11 @@ gpx_wr_init(const char* fname)
   ofd = gbfopen(fname, "w", MYNAME);
 
   writer.setAutoFormattingIndent(2);
-//  writer.setCodec("UTF-8");
-//  writer.writeStartDocument();
+  // Technically, XML (and therefore GPX) defaults ot UTF-8, so we should not
+  // have to declare this.  For compatibility with the existing Qt writer,
+  // we do...
+  //  writer.setCodec("UTF-8");
+  //  writer.writeStartDocument();
   writer.writeProcessingInstruction("xml","version=\"1.0\" encoding=\"UTF-8\"");
 
 }
@@ -1535,31 +1537,21 @@ fprint_xml_chain(xml_tag* tag, const waypoint* wpt)
       }
       if (wpt && wpt->gc_data->exported &&
           strcmp(tag->tagname, "groundspeak:cache") == 0) {
-        xml_write_time(ofd, wpt->gc_data->exported, 0,
-                       "groundspeak:exported");
+        char time_string[64];
+        xml_fill_in_time(time_string, wpt->gc_data->exported, 
+                         0, XML_LONG_TIME);
+        if (time_string[0]) {
+          writer.writeTextElement("time", time_string);
+        }
       }
       writer.writeEndElement();
     }
     if (tag->parentcdata) {
-#if OLDGPX
-      // retain whitespacing, but nuke leading NL as the above will add a trailing.
-
-      char* otmp_ent, *tmp_ent = NULL;
-      otmp_ent = xml_entitize(tag->parentcdata);
-      if (otmp_ent[0] == '\n') {
-        tmp_ent = otmp_ent+1;
-      } else {
-        tmp_ent = otmp_ent;
-      }
-      gbfprintf(ofd, "%s", tmp_ent);
-      xfree(otmp_ent);
-#else
       // FIXME: The length check is necessary to get line endings correct in our test suite.
       // Writing the zero length string eats a newline, at least with Qt 4.6.2.
       if (tag->parentcdatalen > 0) {
         writer.writeCharacters(tag->parentcdata);
       }
-#endif
     }
     tag = tag->sibling;
   }
@@ -1609,28 +1601,6 @@ write_gpx_url(const waypoint* waypointp)
     return;
   }
 
-#if OLDGPX
-  char* tmp_ent;
-  if (gpx_wversion_num > 10) {
-    url_link* tail;
-    for (tail = (url_link*)&waypointp->url_next; tail; tail = tail->url_next) {
-      tmp_ent = xml_entitize(tail->url);
-      gbfprintf(ofd, "  <link href=\"%s%s\">\n",
-                urlbase ? urlbase : "", tmp_ent);
-      write_optional_xml_entity(ofd, "  ", "text",
-                                tail->url_link_text);
-      gbfprintf(ofd, "  </link>\n");
-      xfree(tmp_ent);
-    }
-  } else {
-    tmp_ent = xml_entitize(waypointp->url);
-    gbfprintf(ofd, "  <url>%s%s</url>\n",
-              urlbase ? urlbase : "", tmp_ent);
-    write_optional_xml_entity(ofd, "  ", "urlname",
-                              waypointp->url_link_text);
-    xfree(tmp_ent);
-  }
-#else
   if (gpx_wversion_num > 10) {
     url_link* tail;
     for (tail = (url_link*)&waypointp->url_next; tail; tail = tail->url_next) {
@@ -1647,7 +1617,6 @@ write_gpx_url(const waypoint* waypointp)
   }
   writer.writeTextElement("url", QString(urlbase) + QString(waypointp->url));
   writer.writeOptionalTextElement("urlname", QString(waypointp->url_link_text));
-#endif
 }
 
 /*
@@ -1728,36 +1697,6 @@ gpx_write_common_extensions(const waypoint* waypointp, const char* indent)
   // FIXME: Although not required by the schema it seems gpxtpx:TrackPointExtension should only be used as a child of gpx:trkpt
   if (((opt_humminbirdext || opt_garminext) && (waypointp->depth != 0 || waypointp->temperature != 0))
       || (opt_garminext && (waypointp->heartrate != 0 || waypointp->cadence != 0))) {
-#if OLDGPX
-    gbfprintf(ofd, "%s<extensions>\n", indent);
-    if (waypointp->depth != 0) {
-      if (opt_humminbirdext)
-        gbfprintf(ofd, "%s  <h:depth>%f</h:depth>\n",
-                  indent, waypointp->depth*100.0);
-      if (opt_garminext)
-        gbfprintf(ofd, "%s  <gpxx:Depth>%f</gpxx:Depth>\n",
-                  indent, waypointp->depth);
-    }
-    if (waypointp->temperature != 0) {
-      if (opt_humminbirdext)
-        gbfprintf(ofd, "%s  <h:temperature>%f</h:temperature>\n",
-                  indent, waypointp->temperature);
-      if (opt_garminext)
-        gbfprintf(ofd, "%s  <gpxx:Temperature>%f</gpxx:Temperature>\n",
-                  indent, waypointp->temperature);
-    }
-    if (opt_garminext && (waypointp->heartrate != 0 || waypointp->cadence != 0)) {
-      gbfprintf(ofd, "%s  <gpxtpx:TrackPointExtension>\n", indent);
-      if (waypointp->heartrate != 0)
-        gbfprintf(ofd, "%s    <gpxtpx:hr>%u</gpxtpx:hr>\n",
-                  indent, waypointp->heartrate);
-      if (waypointp->cadence != 0)
-        gbfprintf(ofd, "%s    <gpxtpx:cad>%u</gpxtpx:cad>\n",
-                  indent, waypointp->cadence);
-      gbfprintf(ofd, "%s  </gpxtpx:TrackPointExtension>\n", indent);
-    }
-    gbfprintf(ofd, "%s</extensions>\n", indent);
-#else
     writer.writeStartElement("extensions");
     if (waypointp->depth != 0) {
       if (opt_humminbirdext) {
@@ -1786,7 +1725,6 @@ gpx_write_common_extensions(const waypoint* waypointp, const char* indent)
       writer.writeEndElement(); // "gpxtpx:TrackPointExtension"
     }
     writer.writeEndElement(); // "extensions"
-#endif
   }
 }
 
@@ -1833,7 +1771,7 @@ gpx_waypt_pr(const waypoint* waypointp)
     }
     if (gmsd && (gpx_wversion_num > 10)) {
       /* MapSource doesn't accepts extensions from 1.0 */
-      garmin_fs_xml_fprint(ofd, waypointp, writer);
+      garmin_fs_xml_fprint(waypointp, writer);
     }
   } else {
     gpx_write_common_extensions(waypointp, "  ");
@@ -1846,29 +1784,22 @@ gpx_track_hdr(const route_head* rte)
 {
   fs_xml* fs_gpx;
   current_trk_head = rte;
-#if OLDGPX
-  gbfprintf(ofd, "<trk>\n");
-  write_optional_xml_entity(ofd, "  ", "name", rte->rte_name);
-  write_optional_xml_entity(ofd, "  ", "desc", rte->rte_desc);
+
+  writer.writeStartElement("trk");
+  writer.writeOptionalTextElement("name", rte->rte_name);
+  writer.writeOptionalTextElement("desc", rte->rte_desc);
   if (rte->rte_num) {
-    gbfprintf(ofd, "<number>%d</number>\n", rte->rte_num);
+    writer.writeTextElement("number", QString::number(rte->rte_num));
   }
 
+  // FIXME: Note that this chain nonsense is not executed in our
+  // test suite as of 2013-03-09.
   if (gpx_wversion_num > 10) {
     fs_gpx = (fs_xml*)fs_chain_find(rte->fs, FS_GPX);
     if (fs_gpx) {
       fprint_xml_chain(fs_gpx->tag, NULL);
     }
   }
-#else
-  writer.writeStartElement("trk");
-  writer.writeOptionalTextElement("name", rte->rte_name);
-  writer.writeOptionalTextElement("desc", rte->rte_desc);
-  if (rte->rte_num) {
-    writer.writeTextElement("number", QString::number(rte->rte_num));
-  }
-  // TODO the chain nonsense.
-#endif
 }
 
 static void
@@ -2071,12 +2002,6 @@ gpx_write(void)
     fatal(MYNAME ": gpx version number of '%s' not valid.\n", gpx_wversion);
   }
 
-#if OLDGPX
-  gbfprintf(ofd, "<?xml version=\"1.0\" encoding=\"%s\"?>\n", global_opts.charset_name);
-  gbfprintf(ofd, "<gpx\n  version=\"%s\"\n", gpx_wversion);
-  gbfprintf(ofd, "  creator=\"" CREATOR_NAME_URL "\"\n");
-  gbfprintf(ofd, "  xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
-#else
   // FIXME: This write of a blank line is needed for Qt 4.6 (as on Centos 6.3)
   // to include just enough whitespace between <xml/> and <gpx...> to pass
   // diff -w.  It's here for now to shim compatibility with our zillion
@@ -2088,47 +2013,26 @@ gpx_write(void)
   writer.writeAttribute("\n  version", gpx_wversion);
   writer.writeAttribute("\n  creator", CREATOR_NAME_URL);
   writer.writeAttribute("\n  xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
-#endif
 
-  // FIXME: If we pass elements from an optional declared namespace, e.g. gpxx, gpxtpx, or h through with fprint_xml_chain, we won't have declared the namespace.
+  // FIXME: If we pass elements from an optional declared namespace, 
+  // e.g. gpxx, gpxtpx, or h through with fprint_xml_chain, we won't 
+  // have declared the namespace.
   //        This is a schema violation.
   if (opt_humminbirdext) {
-#if OLDGPX
-    gbfprintf(ofd, "  xmlns:h=\"http://humminbird.com\"\n");
-#else
     writer.writeAttribute("\n  xmlns:h","http://humminbird.com");
-#endif
   }
   if (opt_garminext) {
-#if OLDGPX
-    gbfprintf(ofd, "  xmlns:gpxx=\"http://www.garmin.com/xmlschemas/GpxExtensions/v3\"\n"
-              "  xmlns:gpxtpx=\"http://www.garmin.com/xmlschemas/TrackPointExtension/v1\"\n");
-#else
+    // TODO: it's kind of wrong to force formatting in here...
     writer.writeAttribute("\n  xmlns:gpxx", "http://www.garmin.com/xmlschemas/GpxExtensions/v3");
     writer.writeAttribute("\n  xmlns:gpxtpx", "http://www.garmin.com/xmlschemas/TrackPointExtension/v1");
-#endif
   }
-#if OLDGPX
-  gbfprintf(ofd, "  xmlns=\"http://www.topografix.com/GPX/%c/%c\"\n", gpx_wversion[0], gpx_wversion[2]);
-#else
   writer.writeAttribute("\n  xmlns", QString("http://www.topografix.com/GPX/%1/%2").arg(gpx_wversion[0]).arg(gpx_wversion[2]));
-#endif
   if (xsi_schema_loc) {
-#if OLDGPX
-    gbfprintf(ofd, "  xsi:schemaLocation=\"%s\">\n", xsi_schema_loc);
-#else
+    // FIXME: it's tacky to have formatting in here...
     writer.writeAttribute("\n  xsi:schemaLocation", xsi_schema_loc);
-#endif
   } else {
-#if OLDGPX
-    gbfprintf(ofd,
-              "  xsi:schemaLocation=" DEFAULT_XSI_SCHEMA_LOC_FMT">\n",
-              gpx_wversion[0], gpx_wversion[2],
-              gpx_wversion[0], gpx_wversion[2]);
-#else
     writer.writeAttribute("\n  xsi:schemaLocation",
                           QString("http://www.topografix.com/GPX/%1/%2 http://www.topografix.com/GPX/%1/%2/gpx.xsd").arg(gpx_wversion[0]).arg(gpx_wversion[2]));
-#endif
   }
 
   if (gpx_wversion_num > 10) {
@@ -2150,15 +2054,11 @@ gpx_write(void)
   }
 
   now = current_time();
-#if OLDGPX
-  xml_write_time(ofd, now, 0, "time");
-#else
   char time_string[64];
   xml_fill_in_time(time_string, now, 0, XML_LONG_TIME);
   if (time_string[0]) {
     writer.writeTextElement("time", time_string);
   }
-#endif
   gpx_write_gdata(&gpx_global->keywords, "keywords");
 
   gpx_write_bounds();